package handler

import (
	"google.golang.org/protobuf/types/dynamicpb"
	"sen-golang-study/go_game_study/hero_story_go_server/biz_server/service/user/userdata"
	"sen-golang-study/go_game_study/hero_story_go_server/common/log"
	"sen-golang-study/go_game_study/hero_story_go_server/common/server_msg/proto_msg"
)

func handleCmdUserEntry(ctx CmdContext, _ *dynamicpb.Message) {
	if nil == ctx || ctx.GetUserId() <= 0 {
		return
	}

	log.Info("收到用户入场消息！userId = %d", ctx.GetUserId())

	user := userdata.GetUserGroup().GetByUserId(ctx.GetUserId())

	if user == nil {
		log.Error("未找到用户数据，userId = %d", ctx.GetUserId())
		return
	}

	userEntryResult := proto_msg.UserEntryResult{
		UserId:     user.UserId,
		UserName:   user.UserName,
		HeroAvatar: user.HeroAvatar,
	}

	GetCmdContextGroup().Broadcast(&userEntryResult)
}
